﻿using gecommon;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace geagent
{
    //每个Agent代表当前已经登录的角色 每个角色的消息应该排队依次处理
    //边界触发队列太难写了 用ContinueWith来代替 close后所有的Task应该尽快完成
    public class Agent
    {
        private Task _current = null;

        //gracefully 为true 会把接受队列里的消息都处理完再退出
        //为false则尽快退出
        public async Task Close()
        {
            //string mysqlConnectionString = "Server=localhost;Database=csharp;Uid=root;Pwd=admin";
            //MySqlConnection conn = new MySqlConnection(mysqlConnectionString);
            //MySqlCommand command;
            //command = conn.CreateCommand();
            //command.ExecuteNonQuery();
            //await Task<int>.Factory.FromAsync(command.BeginExecuteNonQuery(), command.EndExecuteNonQuery);
        }

        public void Enqueue(object req)
        {
            var task = _current.ContinueWith((t)=> { });
           //task.ContinueWith
            //if ()
            ////入队
            //_queue.Enqueue(req);
            //if (_current.IsCompleted)
            //{
            //    _current = new Task(() => { });
            //}
            //Task.Factory.
        }
    }
}
